package com.cskaoyan.servlet;

import com.cskaoyan.bean.MarketFeedback;
import com.cskaoyan.bean.common.BaseRespVo;
import com.cskaoyan.bean.common.CommonData;
import com.cskaoyan.service.AdminFeedbackService;
import com.cskaoyan.service.AdminFeedbackServiceimpl;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @author Ramsey
 * @date 2023年05月28日 17:28
 */
@WebServlet("/admin/feedback/*")
public class AdminFeedbackServlet extends WdBaseServlet {
    AdminFeedbackService adminFeedbackService = new AdminFeedbackServiceimpl();

    public BaseRespVo list(HttpServletRequest request, HttpServletResponse response) {
        //是不是都有的
        Integer page = Integer.parseInt(request.getParameter("page"));
        Integer limit = Integer.parseInt(request.getParameter("limit"));
        String order = request.getParameter("order");
        String sort = request.getParameter("sort");
        //请求的
        String username = request.getParameter("username");
        String id = request.getParameter("id");
        //
        CommonData data = adminFeedbackService.query(page, limit, sort, order);
        //
        System.out.println("---------------------------------测试参数-----------------------------");
        System.out.print("page = " + page);
        System.out.print(" limit = " + limit);
        System.out.print(" order = " + order);
        System.out.print(" sort = " + sort);
        System.out.print(" username = " + username);
        System.out.print(" id = " + id);
        System.out.println();
        //测试情况
        if (username == null && id == null) {
            System.out.println("此时用户名和反馈id都是空的");
            return BaseRespVo.ok(data);
        }
        //根据username来模糊查询的时候（此时id为null或者""）
        if (username != null && ("".equals(username) == false) && (id == null || "".equals(id))) {
            System.out.println("进入根据用户名进行模糊查询");
            List<MarketFeedback> marketSearchHistories = adminFeedbackService.selectByUsername(username);
            CommonData commonData = CommonData.data(marketSearchHistories);
            return BaseRespVo.ok(commonData);
        }
        //根据反馈id来查（在这个返回单条的）
        if (id != null && ("".equals(id) == false) && (username == null || "".equals(username))) {
            System.out.println("进入根据反馈id来查询");
            Integer feedbackId = Integer.parseInt(id);
            List<MarketFeedback> marketSearchHistories = adminFeedbackService.selectByid(feedbackId);
            CommonData commonData = CommonData.data(marketSearchHistories);
            return BaseRespVo.ok(commonData);
        }

        return BaseRespVo.ok(data);
    }
}
